package ArrayList

type StackArrayX interface {
	Clear()                //清空
	Size() int             //大小
	Pop() interface{}      //弹出
	Push(data interface{}) //压入
	IsFull() bool          //是否满了
	IsEmpty() bool         //是否为空
	Iterator() Iterator
}

type StackX struct {
	myarray List //数组
	//myit Iterator
}

func NewArrayListStackX() StackArrayX {
	stack := new(StackX)
	stack.myarray = NewArrayList()
	//stack.myit = stack.myarray.Iterator() //迭代
	return stack
}

func(s *StackX) Iterator() Iterator{
	return s.myarray.Iterator()
}

func (s *StackX) Clear() {
	s.myarray.Clear()
}

func (s *StackX) Size() int {
	return s.myarray.Size()
}

func (s *StackX) Pop() interface{} {
	if !s.IsEmpty() {
		last := s.myarray.Last()               //最后一个数据
		s.myarray.Delete(s.myarray.Size() - 1) //删除最后一个
		return last
	}
	return nil
}

func (s *StackX) Push(data interface{}) {
	if !s.IsFull() {
		s.myarray.Append(data)
	}
}

func (s *StackX) IsFull() bool {
	if s.myarray.Size() >= 10 {
		return true
	}
	return false
}

func (s *StackX) IsEmpty() bool {
	if s.myarray.Size() == 0 {
		return true
	}
	return false
}

